
package com.zcp.wizard;

import android.content.Context;
import android.net.wifi.WifiManager;

public class WifiUtils {

    public static boolean toggleWifi(Context context) {
        boolean success = false;
        try {
            WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

            success = wifiManager.setWifiEnabled(!wifiManager.isWifiEnabled());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return success;
    }

    public static boolean isEnable(Context context) {
        boolean success = false;
        try {
            WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            success = wifiManager.isWifiEnabled();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return success;
    }

    public static int getWifiState(Context context) {
        int status = WifiManager.WIFI_STATE_UNKNOWN;
        try {
            WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            status = wifiManager.getWifiState();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return status;
    }
}
